﻿<%@ Page Language="C#" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style type="text/css">
        dl dt {
            background-color: #ff6a00;
            color: white;
        }

        dl dd {
            margin-bottom: 1em;
        }

        dl {
            line-height: 1.5em;
        }
    </style>
    <title></title>
</head>
<body>
    <%
        var act = Request["Action"];
        if (!string.IsNullOrEmpty(act)) { act = act.ToUpper(); }
        var arg = Request["Arg"];
        if (string.IsNullOrEmpty(arg)) { arg = "DEFAULT"; }
        if ("DEBUG" == act)
        {
    %>
    <dl>
        <%
        foreach (var k in Request.ServerVariables.AllKeys)
        {
        %>
        <dt><%=k %></dt>
        <dd><%=Request.ServerVariables[k] %></dd>
        <%
            }
        %>
    </dl>
    <%
    }
    else
    {
        Response.Clear();
        if ("REGISTER" == act)
        {
            Application["RegistedDynamicIP_" + arg] = Request.ServerVariables["REMOTE_ADDR"];
            Response.Write(Request.ServerVariables["REMOTE_ADDR"]);
        }
        else if ("QUERY" == act)
        {
            var rv = Application["RegistedDynamicIP_" + arg];
            if (null != rv)
            {
                Response.Write(rv.ToString());
            }
            else
            {
                Response.Write("ERROR:NotRegisted");
            }
            Response.Flush(); Response.End();
        }
        else {
            Response.Write("ERROR:Usage ?Action=<Register|Query>&Arg=<Key>");
        }
        Response.Flush(); Response.End();
    } 
    %>

    <form id="form1" runat="server">
    </form>
</body>
</html>